package JAVA300.第十章IO;

import java.io.*;

/**
 * 文件字符流
 */

public class IO_Study11_BufferedReader {
    public static void main(String[] args) {
        inputTest("IOTest01.txt");
       // outputTest("outFile11.txt");

    }

    public static void  inputTest(String srcPath){
        File src = new File(srcPath);
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(src) );

            String line = null;
            while((line = reader.readLine()) != null){
                //字符数组--》字符串
                //String str = new String(flush,0,len);
                System.out.println(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (null != reader){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static void outputTest(String destPath)  {
        File file = new File(destPath);
        Writer writer = null;
        try {
            writer = new FileWriter(file);


            String msg = new String("韩圈圈在测试字符流输出");
            //写法1
            char[] datas = msg.toCharArray();
            writer.write(datas,0, datas.length);
            //写法2
            writer.write(msg);
            writer.flush();
            //写法3
            writer.append("韩圈圈在测试字符流输出").append("hhhqqqqq");


        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (null != writer){
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
